package com.aaa.web.service.impl.appstoreserviceimpl;

import com.aaa.entity.Employee;
import com.aaa.entity.appstore.ElectromobileMessage;
import com.aaa.util.EmpUtil;
import com.aaa.web.commons.Result;
import com.aaa.web.commons.SecondCarEntrepotQuery;
import com.aaa.web.dao.appstoredao.ElectromobileDao;
import com.aaa.web.service.appstoreservice.ElectromobileService;
import com.aaa.web.systemconst.ISystemConst;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* @program:
* @description: app商城中电车管理界面
* @author: 许一鑫
* @create: 9:49 2019/1/3
**/
@Service
public class ElectromobileServiceImpl implements ElectromobileService {
    /**自动注入dao*/
    @Autowired
    private ElectromobileDao dao;

    /**获取已经存在的所有的电瓶车商品信息*/
    @Override
    public Map getElectromobileMessage(SecondCarEntrepotQuery query) {
        int page=query.getPage();
        int size=query.getLimit();
        PageHelper.startPage(page,size);
        Map map=new HashMap();
        List<ElectromobileMessage> list =dao.getElectromobileMessage(query);
        map.put("data",list);
        map.put("count", dao.getElectromobilecount(query));
        map.put("code",ISystemConst.SU_COD);
        map.put("msg","");
        return map;

    }

    /**删除电车商品信息*/
    @Override
    public Result delGoods(String goodsname) {
        //设置返回值
        Result result=new Result();
        dao.delGoods(goodsname);
        //提交车主信息成功后返回100
        result.setCode(ISystemConst.SUCCESS_CODE);
        return result;
    }

    /**将新电车商品信息添加入商城信息表*/
    @Override
    public Result addNewCar(ElectromobileMessage e) {
        //设置返回值
        Result result=new Result();
        //获取员工schoolid
        Employee emp= EmpUtil.getEmp();
        //查重，查询是否该商品名重复
        String goodsname=dao.findgoodsname(e.getGoodsname());
        if (goodsname!=null || goodsname!=""){
            //商品名重复则返回200
            result.setCode(ISystemConst.DEFEAT_CODE);
            return result;
        }
        dao.addNewCar(e);
        //商品名不重复则返回100
        result.setCode(ISystemConst.SUCCESS_CODE);
        return result;
    }

}
